home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Eudora 1.3.1 / source / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  4.3 KB  |  182 lines  |  [TEXT/MPS ]

  1. #define FILE_NUM 10
  2. /* Copyright (c) 1990-1992 by the University of Illinois Board of Trustees */
  3. /************************************************************************
  4.  * routines to handle the cursor
  5.  ************************************************************************/
  6. #pragma load EUDORA_LOAD
  7. #define MAX_CURSOR 8
  8. short CStack[MAX_CURSOR+1];
  9. int CSTop = 0;
  10. /************************************************************************
  11.  * CycleBalls - spin the beach ball
  12.  ************************************************************************/
  13. void CycleBalls(void)
  14. {
  15.     static int currentBall= -1;
  16.     static long ticks;
  17.     
  18.     if (TickCount()>ticks)
  19.     {
  20.         ticks = TickCount();
  21.         currentBall = (currentBall+1) % 4;
  22.         if (CStack[CSTop]<BALL_CURS || CStack[CSTop]>BALL_CURS+3)
  23.             PushCursor(BALL_CURS+currentBall);
  24.         else
  25.             SetTopCursor(BALL_CURS+currentBall);
  26.         SFWTC = True;
  27.         GiveTime();
  28.     }
  29. }
  30.  
  31. /************************************************************************
  32.  * CyclePendulum - swing the pendulum
  33.  ************************************************************************/
  34. void CyclePendulum(void)
  35. {
  36.     static int currentPend= -1;
  37.     static int currentDir= 1;
  38.     
  39.     if (currentDir > 0)
  40.     {
  41.         currentPend++;
  42.         if (CStack[CSTop]<PENDULUM_CURS ||
  43.                                  CStack[CSTop]>PENDULUM_CURS+3)
  44.             PushCursor(PENDULUM_CURS+currentPend);
  45.         else
  46.             SetTopCursor(PENDULUM_CURS+currentPend);
  47.         if (currentPend == 3)
  48.         {
  49.             currentPend++;
  50.             currentDir = -1;
  51.         }
  52.     }
  53.     else
  54.     {
  55.         currentPend--;
  56.         if (CStack[CSTop]<PENDULUM_CURS ||
  57.                 CStack[CSTop]>PENDULUM_CURS+3)
  58.             PushCursor(PENDULUM_CURS+currentPend);
  59.         else
  60.             SetTopCursor(PENDULUM_CURS+currentPend);
  61.  
  62.         if (currentPend == 0)
  63.         {
  64.             currentPend--;
  65.             currentDir = 1;
  66.         }
  67.     }
  68.     SFWTC = True;
  69. }
  70.  
  71. /************************************************************************
  72.  * SetCursorByLocation - make the cursor fit the window
  73.  ************************************************************************/
  74. void SetCursorByLocation(void)
  75. {
  76.     MyWindowPtr win;
  77.     Point mouse;
  78.     Rect r;
  79.     SAVE_PORT;
  80.     
  81. #ifdef DEBUG
  82.     if (BUG1) SysBeep(10L);
  83. #endif
  84.     GetPort(&oldPort);
  85.     win = FrontWindow();
  86.     if (win) SetPort(win);
  87.     GetMouse(&mouse);
  88.  
  89.     if (!MouseRgn) MouseRgn = NewRgn();
  90.     SetRectRgn(MouseRgn,-INFINITY/2,-INFINITY/2,INFINITY/2,INFINITY/2);
  91.     if (!win)
  92.         SetMyCursor(0);
  93.     else if (!CursorInRect(mouse,((GrafPtr)win)->portRect,MouseRgn))
  94.         SetMyCursor(arrowCursor);
  95.     else if (IsMyWindow(win))
  96.     {
  97.         SetPort(win);
  98.         r = win->contR;
  99.         r.top = 0;
  100.         
  101.         if (win->cursor)
  102.           (*win->cursor)(mouse);
  103.         else if (win->ste)
  104.             STECursor(win->ste);
  105.         else
  106.         {
  107.             if (CursorInRect(mouse,win->contR,MouseRgn))
  108.             {
  109.                 switch(((WindowPeek)win)->windowKind)
  110.                 {
  111.                     case COMP_WIN:
  112.                         if (mouse.v<win->topMargin)
  113.                         {
  114.                             SetMyCursor(arrowCursor);
  115.                             r.bottom = win->contR.top;
  116.                             break;
  117.                         }
  118.                         else
  119.                             r.top = win->contR.top;
  120.                             /* fall through */
  121.                     default:
  122.                         SetMyCursor(iBeamCursor);
  123.                         break;
  124.                 }
  125.                 RectRgn(MouseRgn,&r);
  126.             }
  127.             else
  128.                 SetMyCursor(arrowCursor);
  129.         }
  130.     }
  131.     GlobalizeRgn(MouseRgn);
  132.     REST_PORT;
  133.     SFWTC = False;
  134. }
  135.  
  136. /************************************************************************
  137.  * SetMyCursor - clear the cursor stack, and set the cursor
  138.  ************************************************************************/
  139. void SetMyCursor(int cursor)
  140. {
  141.     CSTop = 1;
  142.     SetTopCursor(cursor);
  143. }
  144.  
  145. /************************************************************************
  146.  * PushCursor - push a cursor on the stack
  147.  ************************************************************************/
  148. void PushCursor(int cursor)
  149. {
  150.     if (CSTop<MAX_CURSOR) CSTop++;
  151.     SetTopCursor(cursor);
  152.     SFWTC = True;
  153. }
  154.  
  155. /************************************************************************
  156.  * PopCursor - restore to the last cursor on the stack
  157.  ************************************************************************/
  158. void PopCursor(void)
  159. {
  160.     if (CSTop) CSTop--;
  161.     SetTopCursor(CStack[CSTop]);
  162. }
  163.  
  164. /**********************************************************************
  165.  * change cursors
  166.  **********************************************************************/
  167. void SetTopCursor(cursor)
  168. int cursor;
  169. {
  170.     CStack[CSTop] = cursor;
  171.     if (cursor == arrowCursor)
  172.         SetCursor(&qd.arrow);
  173.     else
  174.     {
  175.         Handle curse = GetCursor(cursor);
  176.         short state = HGetState(curse);
  177.         SetCursor(LDRef(curse));
  178.         HSetState(curse,state);
  179.     }
  180. }
  181.  
  182.